from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

SECRET_KEY = 'django-insecure-7cr2*fe2*x8=&5^wbn5em9!%ow74jl!6w=7n!04_ytqm3df_lc'

DEBUG = True

LOGIN_URL='login/'
ALLOWED_HOSTS = []

# 集成 redis 数据库
CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://:123456@127.0.0.1:6379/14",
    }
}

# mysql
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'lovedownload',
        "USER": "root",
        "PASSWORD": "",
        "HOST": "127.0.0.1",
        "PORT": "3306",
        "ATOMIC_REQUESTS": True,  # 给 每一个视图函数 添加 事务管理
    }
}

# 配置媒体资源 设置文件上传的目录
MEDIA_ROOT= BASE_DIR / 'media'

# 访问的媒体资源的前缀
MEDIA_URL = 'media/'

# qq邮箱配置

EMAIL_HOST = "smtp.qq.com"
# 默认 25不安全
EMAIL_PORT = 465
EMAIL_HOST_USER = "2589753582@qq.com"
EMAIL_HOST_PASSWORD = "wgyyjntpubuhecbd"
EMAIL_USE_TLS = False  # 587
EMAIL_USE_SSL = True  # 465
# 默认 发送的邮箱
DEFAULT_FROM_EMAIL = f"haredot<{EMAIL_HOST_USER}>"

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'res.apps.ResConfig',
    'user.apps.UserConfig',
    'message.apps.MessageConfig',
    'sse.apps.SseConfig'
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    # 'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'LoveDownload.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates']
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'LoveDownload.wsgi.application'

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# 解决 8小时 时差
LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_TZ = False

# 关闭 自动添加 斜杠 的功能
# APPEND_SLASH = True


# 访问的静态资源的前缀
STATIC_URL = '/static/'

# 配置静态文件路径
STATICFILES_DIRS = [
    BASE_DIR / "static",
]

#配置 session
# 设置 session 在 浏览器中存储的 Cookie 键名
SESSION_COOKIE_NAME = "sessionid"
# 设置 session的全局过期时间、默认 2周
SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2
# 设置 session对应的 Cookie 的 域
SESSION_COOKIE_DOMAIN = None
# 设置 session对应的 Cookie 的 访问路径
SESSION_COOKIE_PATH = "/"
# 设置 session是否是 会话session (随浏览器的关闭而销毁)
SESSION_EXPIRE_AT_BROWSER_CLOSE = False
# session对象的默认序列化器、该序列化器可以将session中的数据进行序列化，并存储到 django_session表
SESSION_SERIALIZER = "django.contrib.sessions.serializers.JSONSerializer"
#是否 在 每一次 请求 都更新 session 如果设置为 True 可以实现 session自动 续约
SESSION_SAVE_EVERY_REQUEST = False


# Celery 使用 Redis 作为消息队列
CELERY_BROKER_URL = 'redis://:123456@127.0.0.1:6379/5'
CELERY_RESULT_BACKEND = 'redis://:123456@127.0.0.1:6379/6'

# 可选配置
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Asia/Shanghai'



DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
